<?php

class Doctrine_Model_BackupDao {

    public function getEntityManager() {
        if (Zend_Registry::isRegistered('em')) {
            return Zend_Registry::get('em');
        }
        return null;
    }

    public function obtenerTodos() {
        return $this->getEntityManager()
                ->createQuery('select p from Doctrine_Model_Entities_Adjunto p')
                ->getResult();
    }
    
      public function obtenerPorFecha($fecha) {
        return $this->getEntityManager()
                ->createQuery("select b from Doctrine_Model_Entities_Backup b where b.fecha >= '".$fecha." 00:00:00' and b.fecha <= '".$fecha." 23:59:59'")
                ->getResult();
    }
    
    
 
   

    public function obtenerPorId($id) {
        return $this->getEntityManager()->find('Doctrine_Model_Entities_Adjunto', $id);
    }

    
    public function guardar(Doctrine_Model_Entities_Backup $adjunto) {
        try {
            
            $this->getEntityManager()->persist($adjunto);
            $this->getEntityManager()->flush();
            return true;
        } catch (Exception $e) {
            $logger = Zend_Registry::get('logger');
            $logger->log("Error: " . $e->getMessage(), Zend_Log::ERR);
            return false;
        }
    }

    public function eliminar(Doctrine_Model_Entities_Adjunto $nota) {
        try {
            $this->getEntityManager()->remove($nota);
            $this->getEntityManager()->flush();
        
            return true;
        } catch (Exception $e) {
            $logger = Zend_Registry::get('logger');
          
            $logger->log("Error: " . $e->getMessage(), Zend_Log::ERR);
            return false;
        }
    }

   

}

